/*
 * AffixHierarchy.java
 *
 * Created on November 5, 2007, 7:59 AM
 *
 */
package HierarchyPackage.AffixHierarchies;

import HierarchyPackage.*;
import ClassifiedDataSetPackage.ClassifiedDataSet;
import DataSetPackage.View;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Martin Haulrich
 */
abstract class AffixHierarchy implements Hierarchy {

    /**
     * The top-class in the hierarchy.
     * This is equavalent to an empty string.
     */
    AffixHClass top;

    protected void setTop(AffixHClass top) {
        this.top = top;
    }

    @Override
    public HClass getTop() {
        return top;
    }

    @Override
    public synchronized String getName(HClass hc) {

        AffixHClass hcS = (AffixHClass) hc;
        String name = hcS.getID();
        if (name.equals("")) {
            return "TOP";
        } else {
            return name;
        }
    }

    @Override
    abstract public ClassifiedDataSet getClassifications(Collection<Integer> dids, View v,
            HClass topClass, int maxDepth, int minCount, int cutFracgtion, boolean saveData);

    @Override
    abstract public boolean superclassOf(HClass c1, HClass c2);

    @Override
    abstract public boolean isClassifiedBy(Integer did, View dv, HClass classification);

    public abstract HClass getIntersectionLocal(HClass c1, HClass c2);

    @Override
    public Set<HClass> getIntersection(HClass c1, HClass c2) {
        HClass c = getIntersectionLocal(c1, c2);
        Set<HClass> res = new HashSet<HClass>();
        if (c != null) {
            res.add(c);
        }
        return res;
    }

    @Override
    public Set<HClass> getIntersection(HClass[] classes) {

        Set<HClass> result = new HashSet<HClass>();
        HClass res;

        res = classes[0];
        for (int i = 1; (i < classes.length) && (res != null); i++) {
            res = getIntersectionLocal(res, classes[i]);
        }
        if (res != null) {
            result.add(res);
        }

        return result;
    }
}
